package com.utils;

import com.example.com.skills_utf8.R;

import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;


/**
 * 动态给出提示；
 * @author 腾飞
 *
 */
public class UtilsTipView {
	
	private static UtilsTipView mTipView;
	private UtilsTipView(){
		
	}
	
	public static UtilsTipView getInstance(){
		if(mTipView == null){
			mTipView = new UtilsTipView();
		}
		
		return mTipView;
	}

	
	private View toast;	// 要显示的TipView
	public void play(final Activity activity, Handler handler, ViewGroup layout_content){
		
		
		toast = layout_content.findViewWithTag("layout_title_toast");
		if( null ==  toast)
		{
			
			toast = activity.getLayoutInflater().inflate(R.layout.layout_title_toast, null);
			toast.setTag("layout_title_toast");				
			layout_content.addView(toast);
			
		}
		toast.setVisibility(View.VISIBLE);
		handler.postDelayed(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				
				Animation animation = AnimationUtils.loadAnimation(activity, R.anim.fadeout);
				animation.setAnimationListener( new AnimationListener() {
					
					@Override
					public void onAnimationStart(Animation arg0) {
						// TODO Auto-generated method stub
						
					}
					
					@Override
					public void onAnimationRepeat(Animation arg0) {
						// TODO Auto-generated method stub
						
					}
					
					@Override
					public void onAnimationEnd(Animation arg0) {
						// TODO Auto-generated method stub
					
						toast.setVisibility(View.GONE);
					}
				});
				toast.startAnimation(animation);	
				
			}
		}, 2000);
		
		
		
	}
	
	
}
